package com.zhang.dao.impl;

import com.zhang.dao.CategoryDao;
import com.zhang.domain.Category;
import com.zhang.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class CategoryDaoImpl implements CategoryDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(JDBCUtils.getDataSource());


    @Override
    public List<Category> getAll() {
        String sql = "SELECT * FROM `category`";

        List<Category> categorys = null;
        try {
            categorys = jdbcTemplate.query(sql,new BeanPropertyRowMapper<Category>(Category.class));
        } catch (DataAccessException e) {

        }

        return categorys;
    }



}
